package com.csust.automaticteach.utils;

import com.csust.automaticteach.app.entity.DashScopeModel;
import com.csust.automaticteach.app.entity.DashScopeModels;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public final class ModelsUtils {

	private final static String MODELS_FILE_PATH = "models.yaml";//模型配置类

	private static final String MODEL = "model";//键 ：model

	private static final String DESC = "desc";//键 ：desc

	private ModelsUtils() {
	}
	//从models.yaml 读取得到模型列表
	public static Set<Map<String, String>> getDashScopeModels() throws IOException {

		ObjectMapper mapper = new ObjectMapper(new YAMLFactory());// objectMapper
		InputStream resourceAsStream = ModelsUtils.class.getClassLoader().getResourceAsStream(MODELS_FILE_PATH);
		DashScopeModels models = mapper.readValue(resourceAsStream, DashScopeModels.class);

		Set<Map<String, String>> resultSet = new HashSet<>();
		for (DashScopeModel model : models.getDashScope()) {
			Map<String, String> modelMap = new HashMap<>();
			modelMap.put(MODEL, model.getName());
			modelMap.put(DESC, model.getDescription());
			resultSet.add(modelMap);
		}

		return resultSet;
	}

}